//
//  WBStatues.swift
//  weibo
//
//  Created by yanghong on 15/12/11.
//  Copyright © 2015年 杨鸿. All rights reserved.
//

import UIKit

class WBStatues: NSObject {
    // 微博的id
    var id: Int64 = 0
    // 微博的内容
    var text: String?
    // 当前微博作者信息
    var user: WBUser?
    // 微博的创建时间
    var created_at: String?
    // 来自
    var source: String?
    // 转发
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    // 转发微博的内容
    var retweeted_status: WBStatues?
    
    var pic_urls: [WBPicture]?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    // 模型里面嵌套 user 和 statues 这两个模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = WBUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = WBStatues(dict: dict)
            }
        }else if key == "pic_urls" {
            
            if let array = value as? [[String: AnyObject]] {
            
                var temp = [WBPicture]()
                
                for dict in  array {
                
                temp.append(WBPicture(dict: dict))
                
                }
             pic_urls = temp
            
            }
        
        
        }else{
        
        super.setValue(value, forKey: key)
            
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        
        let keys = ["text","user","created_at","source","reposts_count","comments_count","retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
        
    }
}
